
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <style >
       .nianli{
           border: 2px solid red;
           display: grid;/*网格布局*/
           grid-template-columns: repeat(6,auto);/*一行元素的个数，宽度auto */
           gap: 10px;/*容器内各个子元素之间的间距 */
           padding: 10px;/*内边距*/
       }
       .data{
          display: grid;
          grid-template-columns: repeat(7,auto);
       }
       .data > div{
           text-align: center;
           border: 1px solid #ddd;
       }
       .yueli{
           border: 1px solid blue;
           padding: 5px;
       }
       .yue{
           text-align: center;
           color: red;
           font-weight: bold;
           line-height: 2;/*设置行高  也可以用 padding(内边距)  margin（外边距） */
       }
       .title{
           text-align: center;
           font-size: 24px;
           font-weight: bold;
           color: red;
           line-height: 2;
       }
       select{
           width: 160px;
           padding: 8px;
       }
    </style>
    <title>年历</title>
</head>
<body>
<script>
    function nav(value){
        console.log(value,location.href)//列表框当前选项的值及当前页面的网址
        location.href="?year="+value
    }
</script>
<?php
$now=new DateTime();//当前日期时间
$currentYear=$now->format("Y");//当前的年份
$year=$_GET['year']??$currentYear;//显示年历的年份

?>
<div class='kuang'>
    <select onchange="nav(value)"> <!--下拉列表框-->
        <?php
        for($i=$currentYear;$i>$currentYear-10;--$i){
            echo "        <option ",$i==$year?"selected ":"","value='",$i,"'>",$i, "</option>\n";
        }
        ?>
    </select>
    <div class="title"><?=$year?>年</div>
    <div class='nianli'>
        <?php
        for($m=1;$m<=12;$m++){
            echo " <div class='yueli'>";
            echo " <div class='yue'>{$m}月</div>";
            echo " <div class='data'>";
            echo "<div>一</div><div>二</div><div>三</div><div>四</div><div>五</div><div>六</div><div>日</div>";
            $d=new DateTime("$year-$m-1");
            $kong=$d->format('N')-1;//1号前面的空白项的个数
            echo str_repeat("<div></div>",$kong);
            $days=$d->format('t');//天数
            for ($i=1;$i<=$days;$i++){
                echo "<div>$i</div>";
            }
            echo "</div></div>";
        }
        ?>

    </div>
</div>
</body>
</html>
